<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单生成测试（本地开发版）</title>
    <style>
        body {
            font-family: 'Helvetica Neue', Arial, sans-serif;
            line-height: 1.6;
            padding: 20px;
            max-width: 800px;
            margin: 0 auto;
            color: #333;
        }
        h1 {
            text-align: center;
            margin-bottom: 30px;
            color: #1a73e8;
        }
        .container {
            background-color: #f5f5f5;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input, textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 14px;
        }
        button {
            background-color: #1a73e8;
            color: white;
            border: none;
            border-radius: 4px;
            padding: 10px 15px;
            cursor: pointer;
            font-size: 14px;
            margin-top: 10px;
        }
        button:hover {
            background-color: #155cbf;
        }
        pre {
            background-color: #f8f8f8;
            padding: 15px;
            border-radius: 4px;
            overflow-x: auto;
            margin-top: 20px;
        }
        .note {
            background-color: #fff3cd;
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <h1>订单生成测试（本地开发版）</h1>
    
    <div class="note">
        <strong>注意：</strong> 此简化版本只能通过Web服务器访问，请不要直接在文件系统打开。
    </div>
    
    <div class="container">
        <div class="form-group">
            <label for="token">授权Token:</label>
            <input type="text" id="token" placeholder="请输入有效的JWT Token">
        </div>
        
        <div class="form-group">
            <label for="bookId">书籍ID:</label>
            <input type="number" id="bookId" placeholder="请输入书籍ID">
        </div>
        
        <div class="form-group">
            <label for="remark">订单备注:</label>
            <textarea id="remark" rows="3" placeholder="请输入订单备注信息（可选）"></textarea>
        </div>
        
        <button id="generateBtn">生成订单</button>
        
        <pre id="result">结果将显示在这里...</pre>
    </div>

    <script>
        document.getElementById('generateBtn').addEventListener('click', function() {
            const token = document.getElementById('token').value.trim();
            const bookId = document.getElementById('bookId').value.trim();
            const remark = document.getElementById('remark').value.trim();
            const resultElement = document.getElementById('result');
            
            if (!token) {
                resultElement.textContent = '错误: 请输入有效的JWT Token';
                return;
            }
            
            if (!bookId) {
                resultElement.textContent = '错误: 请输入书籍ID';
                return;
            }
            
            const apiUrl = 'http://localhost:8080/api/orders/generate';
            
            const orderData = {
                books: [{ book_id: parseInt(bookId) }],
                remark: remark
            };
            
            resultElement.textContent = '请求中...';
            
            fetch(apiUrl, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': token
                },
                body: JSON.stringify(orderData)
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error(`HTTP错误 ${response.status}: ${response.statusText}`);
                }
                return response.json();
            })
            .then(data => {
                resultElement.textContent = JSON.stringify(data, null, 2);
            })
            .catch(error => {
                resultElement.textContent = '请求错误: ' + error.message;
            });
        });
    </script>
</body>
</html> 